<?php
	if (!session_start()) session_start();
	if (!isset($_SESSION['kiemtradangnhapthinguyet']) || $_SESSION['kiemtradangnhapthinguyet']!=1) {
		header('location: ../../../index.php');
		die();
	}
	$user_dangnhap = $_SESSION["taikhoandangnhapthinguyet"];
	if ($user_dangnhap['idgroup']!="1" && $user_dangnhap['idgroup']!="-1") {
		header('location: index.php');
		die();
	}
	
	$table = "user";
?>
<script>
$(document).ready(function() {

	$("#chonhet").click(function(){
		var status=this.checked;
		$("input[name='chon']").each(function(){this.checked=status;})
	});

	$("#xoahet").click(function(){
		var listid="";
		$("input[name='chon']").each(function() {
			if (this.checked) listid = listid+","+this.value;
	    })
		listid=listid.substr(1);	 
		if (listid=="") { alert("You have not selected !"); return; }
		hoi= confirm("Delete all ?");
		if (hoi==true) 
			document.location = "do_delete_list_record.php?table=<?php echo $table; ?>&p=<?php echo $table; ?>_quanly&listid=" + listid;
	});
	
});
</script>	

            	<div class="dangnhap_title">
                <a href="index.php" style="color:#F8991D;" title="Trang chủ">Trang chủ</a>
                <span style="font-size:9px;">>></span> 
                Hệ thống
                <span style="font-size:9px;">>></span> 
                <a href="index.php?p=<?php echo $table; ?>_quanly" style="color:#F8991D;">Thành viên</a> 
            	</div>
            	<?php 
                	$records_per_page = 8;
                	$text =$_GET['text'];
                	if (isset($_POST['text']))
                		$text =$_POST['text'];
					$count = $class_user->get_max_count($text);
                    $page = 1;	
                    $page_count = intval($count/$records_per_page);
                    if ($count/$records_per_page>intval($count/$records_per_page))
						$page_count = $page_count+1;
					if(isset($_GET['page']) && $_GET['page'] <= $page_count)
						$page = $_GET['page'];		
					
					$offset = ($page-1)*$records_per_page;
					
					$list_user = $class_user->get_by_thutu_limit($offset, $records_per_page, $text); 
					$dem=$offset;
                ?>
                  
                <div style="float:right; width:710px; text-align:right;">
                	<form method="post" action="index.php?p=<?php echo $table; ?>_quanly">
                    	<b>Key words:</b> <input type="text" name="text" />
                        <input type="submit" value="Sreach">
                    </form>
                </div>
                
                <div style="float:right; width:710px; position: relative;">
                	<input title="Chọn rồi bấm xóa" type="button" name="xoahet" id="xoahet" value=" Xoá nhiều " class="nut" style="float:left; margin-top:24px;" />
                    <div class="phan_trang">
                    	<?php $db->get_short_page($table,$page,$page_count,$text); ?>
                    </div>
                    <img src="imgs/them.png" onclick="create_record('<?php echo $table; ?>_them');" width="48" height="48" border="0" style="cursor: pointer; float:right;" />
                </div>
                <table border="0" cellpadding="0" cellspacing="0" style="float:right; width:710px; text-align:left;">
                	<tr>
                    	<td width="40" class="td_style1"><input type="checkbox" name="chonhet" id="chonhet" /></td>
                    	<td width="50" class="td_style1"><b>Số</b></td>
                    	<td width="100" class="td_style1"><b>Username</b></td>
                        <td class="td_style1"><b>Thông tin</b></td>
                        <td width="20" class="td_style1" style="padding-right:10px;"><b>Admin</b></td>
                        <td width="20" class="td_style1" style="padding-right:10px;"><b>Block</b></td>
                        <td width="80" class="td_style1" align="center"><b>Công cụ</b></td>
                    </tr>
                    <?php
						foreach ($list_user as $row) {
							$dem++;
							$id = $row["id"];
							$anhien = $row["anhien"];
							$idgroup = $row["idgroup"];
							
							$alt_anhien = "true";
							$src_anhien = "imgs/anhien_1.jpg";
							if ($anhien == 0) {
								$alt_anhien = "false";
								$src_anhien = "imgs/anhien_0.jpg";
							}
							
							$alt_idgroup = "true";
							$src_idgroup = "imgs/anhien_1.jpg";
							if ($idgroup == 0) {
								$alt_idgroup = "false";
								$src_idgroup = "imgs/anhien_0.jpg";
							}
							
					?>
                    <tr>
                    	<td class="td_style2"><input type="checkbox" name="chon" id="chon" value="<?php echo $id; ?>" class="chon" /></td>
                    	<td class="td_style2"><?php echo $dem; ?></td>
                    	<td class="td_style2">
                            <b><?php echo $row['username']; ?></b>
                        </td>
                        <td class="td_style2">
                            <b>Full name:</b> <?php echo $row['hoten']; ?> <br/>
                            <b>Phone:</b> <?php echo $row['dienthoai']; ?> <br/>
                            <b>Email:</b> <?php echo $row['email']; ?> <br/>
                            <b>Adress:</b> <?php echo $row['diachi']; ?>
                        </td>
                        <td class="td_style2" align="center" style="padding-right:10px;">
							<img alt="<?php echo $alt_idgroup; ?>" id="idgroup<?php echo $id; ?>" onclick="do_change_true_false('<?php echo $table; ?>','<?php echo $id; ?>','idgroup');" src="<?php echo $src_idgroup; ?>" border="0" style="cursor: pointer;" />
                        </td>
                        <td class="td_style2" align="center" style="padding-right:10px;">
							<img alt="<?php echo $alt_anhien; ?>" id="anhien<?php echo $id; ?>" onclick="do_change_true_false('<?php echo $table; ?>','<?php echo $id; ?>','anhien');" src="<?php echo $src_anhien; ?>" border="0" style="cursor: pointer;" />
                        </td>
                        <td class="td_style2" align="center">
                       		<img src="imgs/pencil.png" onclick="update_record('<?php echo $table; ?>_sua','<?php echo $id; ?>');" width="16" height="16" border="0" style="cursor: pointer;" />
                            &nbsp;&nbsp;
                            <img src="imgs/xoa.png" onclick="if (confirm('Are you sure ?')) do_delete_record('<?php echo $table; ?>','<?php echo $id; ?>');" width="16" height="16" border="0" style="cursor: pointer;" /> 
                        </td>
                    </tr>
                    <?php
						}
					?>
                </table>